{% extends 'base/base.html' %}

{% block title %}{{ title }} - {{ project.name }} - 多用户报警系统{% endblock %}

{% block content %}
<div class="row justify-content-center">
    <div class="col-md-6">
        <div class="card">
            <div class="card-header">
                <h2 class="h4">
                    <i class="fa fa-plus" aria-hidden="true"></i> {{ title }}
                </h2>
            </div>
            <div class="card-body">
                <form method="post">
                    {% csrf_token %}
                    {% if form.errors %}
                        <div class="alert alert-danger" role="alert">
                            <i class="fa fa-exclamation-circle" aria-hidden="true"></i> 请检查以下错误并重新提交表单。
                        </div>
                    {% endif %}
                    <div class="mb-3">
                        <label for="id_name" class="form-label">
                            <i class="fa fa-tag" aria-hidden="true"></i> 标签名称 <span class="text-danger">*</span>
                        </label>
                        {{ form.name }}
                        {% if form.name.errors %}
                            <div class="text-danger mt-1">
                                {% for error in form.name.errors %}
                                    <i class="fa fa-exclamation-triangle" aria-hidden="true"></i> {{ error }}
                                {% endfor %}
                            </div>
                        {% endif %}
                    </div>
                    <div class="mb-4">
                        <label for="id_color" class="form-label">
                            <i class="fa fa-paint-brush" aria-hidden="true"></i> 标签颜色 <span class="text-danger">*</span>
                        </label>
                        {{ form.color }}
                        {% if form.color.errors %}
                            <div class="text-danger mt-1">
                                {% for error in form.color.errors %}
                                    <i class="fa fa-exclamation-triangle" aria-hidden="true"></i> {{ error }}
                                {% endfor %}
                            </div>
                        {% endif %}
                    </div>
                    <div class="d-flex gap-2">
                        <button type="submit" class="btn btn-primary">
                            <i class="fa fa-check" aria-hidden="true"></i> 保存
                        </button>
                        <a href="{% url 'projects:project_tags' project.id %}" class="btn btn-secondary">
                            <i class="fa fa-times" aria-hidden="true"></i> 取消
                        </a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block javascript %}
<script>
    // 添加页面加载动画效果
    document.addEventListener('DOMContentLoaded', function() {
        // 为表单元素添加焦点效果
        const formInputs = document.querySelectorAll('.form-control');
        formInputs.forEach(input => {
            input.addEventListener('focus', function() {
                this.parentElement.classList.add('shadow-sm');
            });
            input.addEventListener('blur', function() {
                this.parentElement.classList.remove('shadow-sm');
            });
        });
        
        // 为颜色选择框添加预览效果
        const colorSelect = document.getElementById('id_color');
        if (colorSelect) {
            // 创建颜色预览元素
            const colorPreview = document.createElement('div');
            colorPreview.className = 'mt-2 p-2 rounded border';
            colorPreview.style.backgroundColor = colorSelect.value;
            colorPreview.style.minHeight = '30px';
            colorSelect.parentNode.appendChild(colorPreview);
            
            // 添加选择事件监听
            colorSelect.addEventListener('change', function() {
                colorPreview.style.backgroundColor = this.value;
            });
        }
    });
</script>
{% endblock %}